class ApplicationController < ActionController::API
  before_action :authenticate_request
  attr_reader :current_user

  private

  def authenticate_request
    @current_user = AuthorizeApiRequest.call(request.headers).result
    #when authorized failed
    err_return(:unauthorized,status: 401) unless @current_user
  end

  def err_return(status, opts={})
    render head: status, status: opts[:status]
  end

  def obj_return(object, opts={})
    render json: object, status: opts[:status] if opts[:adapter]
    render json: object, status: opts[:status], serializer: opts[:adapter] unless opts[:adapter]
  end

end
